#{extends 'adminm/frame.html' /}

#{set 'moreScripts'}
<script src="@{'/public/javascripts/jquery-ui-1.8.10.custom.min.js'}" type="text/javascript" charset="utf-8"></script>
<script src="@{'/public/pager/jquery.pager.js'}" type="text/javascript" charset="utf-8"></script>
#{/set}
#{set 'moreStyles'}
<link rel="stylesheet" type="text/css" media="screen" href="@{'/public/pager/Pager.css'}" />
<link rel="stylesheet" type="text/css" media="screen" href="@{'/public/stylesheets/table.scss'}" />
<link rel="stylesheet" type="text/css" media="screen" href="@{'/public/stylesheets/Users/message.scss'}" />
#{/set}
#{set 'activeItem'}5#{/set}

<div class="navigationBar">
	<table>
		<tr>
			<td><img src="@{'/public/images/navigationHouse.gif'}"></td>
			<td><strong>当前位置：</strong></td>
			<td>
				<a href="/admin">首页</a>
				>>
				<a href="#">订单管理</a>
				>>
				<font class="current">其他消息</font>
			</td>
		</tr>
	</table>
</div>
<script language="javascript">
$(function(){
	//载入消息列表
	reloadTable();
	//初始化回复窗口
	$("#dialog-form").dialog(
		{
			autoOpen:false,
			modal:true,
    		buttons:{提交:function(){
    				reback();
    				$(this).dialog('close');
    			}
    		}
		}
	);
});

//打开回复窗口
function openDialog(id){
   $("#rebackidId").val(id);
   $("#rebackContentId").val("");
   $("#dialog-form").dialog("open");
}

//回复 留言
function reback() {
	var rebackid = $("#rebackidId").val();
	var rebackContent = $("#rebackContentId").val();

	$.ajax({
		url: "/admin/message/reply",
		data: "rebackid="+rebackid+"&"+"rebackContent="+rebackContent,
		type: "PUT",
		complete: function() {
			reloadTable();
		}
	});
}

//删除 留言
function removeItem(id) {
	$.ajax({
		url: "/admin/message/"+id,
		//data: "id="+id,
		type: "DELETE",
		complete: function() {
			reloadTable();
		}
	});
}

//重新载入listtable。
function reloadTable() {
	var dataStr = getSearchCriteria();
	$.ajax({
		url: "/admin/message/index/others",
		data: dataStr,
		type: "POST",
		dataType: "html",
		complete: function(XMLHttpRequest, textStatus, errorThrown) {
			if(textStatus == "error") {
				var errJson = eval("("+XMLHttpRequest.responseText+")");
				var errMsg = "操作失败，"+errJson.message;
				$("#errMsg").html(errMsg);
				alert(errMsg);
			} else {
				$("#tableDiv").html(XMLHttpRequest.responseText);
				initialPager();
			}
		}
	});
}

//组装查询条件与页码数据。
function getSearchCriteria(toPage) {
	var dataStr="";
	var elements = $(".queryBean");
	if(elements && elements.length!=0) {
		for(var i=0 ; i<elements.length ; i++) {
			if(dataStr) dataStr = dataStr+"&";
			if(elements[i].name != "queryBean.currentPage" || !toPage) {
				dataStr = dataStr + elements[i].name + "=" + $(elements[i]).val();
			}
		}
	}
	if(toPage) {
		if(dataStr) dataStr = dataStr+"&";
		dataStr = dataStr + "queryBean.currentPage=" + toPage;
	}
	return dataStr;
}
</script>
<div id="errMsg" class="error">
	${errMsg}
	#{error 'errMsg'/}
</div>
<div class="list_criteria">
	<input type="hidden" id="currentPage" class="queryBean" name="queryBean.currentPage" value="1">
	每页
	<select name="queryBean.quantityEachPage" class="queryBean" onChange="reloadTable()">
		<option value="2">2</option>
		<option value="10" selected>10</option>
		<option value="25">25</option>
		<option value="50">50</option>
	</select>
	条记录
	&nbsp;&nbsp;&nbsp;
	按照
	<select name="queryBean.orderby" class="queryBean" onChange="reloadTable()">
		<option value="lastModifiedAt" selected>修改日期</option>
		<option value="type">类型</option>
		<option value="author">留言者</option>
		<option value="content">内容</option>
	</select>
	<select name="queryBean.isDesc" class="queryBean" onChange="reloadTable()">
		<option value="true" selected>降序</option>
		<option value="false">升序</option>
	</select>
	排序
	&nbsp;&nbsp;&nbsp;
	关键字
	<input type="text" maxlength="20" name="queryBean.keyword" value="" class="queryBean" onChange="reloadTable()">
	&nbsp;&nbsp;&nbsp;
	<select name="messageType" class="queryBean" onChange="reloadTable()">
		<option value="" selected>全部</option>
		<option value="CONSULTING">咨询</option>
		<option value="SUGGEST">建议</option>
		<option value="OTHER">其他</option>
	</select>
</div>
<div id="tableDiv"></div>

<div id="dialog-form" class="ui-widget ui-widget-content ui-corner-all div_reback" title="留言回复">
    <form id="login-form">
    <input type="hidden" id="rebackidId" name="rebackid">
    <textarea wrap="virtual" rows="4"
        cols="50" id="rebackContentId" name="rebackContent"></textarea>
    </form>
</div>